package com.qf.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.io.File;

@Controller
@RequestMapping("/file")
public class FileController {
    @RequestMapping("/upload")
    public String upload(String name, MultipartFile file, HttpSession session)throws Exception{
        String path = session.getServletContext().getRealPath("/upload");
        File dir=new File(path);
        if (!dir.exists()){
            dir.mkdirs();
        }
        String filename = file.getOriginalFilename();
        System.out.println(filename);
        file.transferTo(new File(path+File.separator+filename));
        return "/success.jsp";
    }
}
